package com.fang.algorithm.zuo.tree;

/**
 * @author lingxiao.fang
 * @Desc 二叉树的左中右序遍历 递归
 * 递归序
 * @createTime 2025/2/26 09:39
 */
public class Test01_LeftRightMidTree_Heap {

    private static class NodeTree {
        private Integer value;
        private NodeTree left;
        private NodeTree right;

        public NodeTree(Integer value) {
            this.value = value;
        }
    }

    public static void main(String[] args) {
        NodeTree head = new NodeTree(1);
        head.left = new NodeTree(2);
        head.right = new NodeTree(3);
        head.left.left = new NodeTree(4);
        head.left.right = new NodeTree(5);
        head.right.left = new NodeTree(6);
        head.right.right = new NodeTree(7);
        // 二叉树的左序遍历
//        leftTree(head);
        // 二叉树的中序遍历
//        midTree(head);
        // 二叉树的右序遍历
        rightTree(head);
    }

    private static void leftTree(NodeTree head) {
        if (head == null) {
            return;
        }
        System.out.println(head.value);
        leftTree(head.left);
        leftTree(head.right);
    }

    private static void midTree(NodeTree head) {
        if (head == null) {
            return;
        }
        leftTree(head.left);
        System.out.println(head.value);
        leftTree(head.right);
    }

    private static void rightTree(NodeTree head) {
        if (head == null) {
            return;
        }
        leftTree(head.left);
        leftTree(head.right);
        System.out.println(head.value);
    }
}
